package com.example.kafka.comsumer;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;


@Component
public class KafkaConsumer {

	private static final Logger LOGGER = LoggerFactory.getLogger(KafkaConsumer.class);

	/**
	 * 接收kafka消息
	 */
	@KafkaListener(id = "demo", topics = "topic1")
    public void listen(String msgData) {
        System.out.println("demo receive : "+msgData);
    }

	/**
	 * 使用ConsumerRecord接收消息
	 * 可以包含分区信息，消息头，消息体等内容
	 * @param record
	 */
	@KafkaListener(id = "consumer", topics = "topic.quick.consumer")
    public void recodeListener(ConsumerRecord<Integer, String> record) {
		LOGGER.info("topic.quick.consumer receive: " + record.toString());
	}

}
